﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using hospital_registration_system.Entity;
using hospital_registration_system.DAL;
using LinkSql;

namespace hospital_registration_system.BLL
{
    /// <summary>
    /// 时段表服务
    /// </summary>
    public class Clinic_TimeService
    {
        protected Clinic_timeDao dao = null;
        public Clinic_TimeService()
        {
            dao = new Clinic_timeDao();
        }
        /// <summary>
        /// 查找所有的就诊时间安排
        /// </summary>
        /// <returns>返回所有就诊时间的链表</returns>
        public List<Clinic_time> selectAllClinic_time()
        {
            return dao.selectAll();
        }

        /// <summary>
        /// 删除就诊时间安排
        /// </summary>
        /// <param name="id">要删除的就诊时间安排的id</param>
        /// <returns>操作信息</returns>
        public bool deleteClinic_timeById(int id)
        {
            if (id < 0) return false;//检查id属性是否符合要求
            return dao.delete(id);
        }

        /// <summary>
        /// 修改就诊时间安排
        /// </summary>
        /// <param name="departments">修改后的就诊时间安排</param>
        /// <returns>操作信息</returns>
        public bool updateClinic_time(Clinic_time time)
        {
            if (time == null || time.Id < 0)
            {
                return false;
            }
            return dao.updateByObject(time);
        }

        /// <summary>
        /// 插入一条医生的就诊时间安排
        /// </summary>
        /// <param name="name"></param>
        /// <returns>操作信息</returns>
        public bool insertClinic_time(int id, DateTime treatment, int see_time)
        {
            return dao.insert(id, treatment, see_time);
        }

        /// <summary>
        /// 通过时间和科室id查询预约时段
        /// </summary>
        /// <param name="time">查询的日期</param>
        /// <param name="keshi_id">查询的时段</param>
        /// <returns>查询到的结果</returns>
        public List<Clinic_time> findClinic_TimeByDateAndDepartmentsId(DateTime time, int keshi_id)
        {
            if (time.Ticks < DateTime.Now.Ticks)//检查输入的预约时间是否在当天之前
            {
                return null;
            }
            return dao.GetClinic_Times(time, keshi_id);
        }
    }
}
